/*
 * Created by JFormDesigner on Sat Apr 23 16:41:15 CST 2022
 */

package View;

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;

import Factory.CalculateClassFactory;
import Factory.ENUM.CAL_MODE;
import Model.DrawModel.CalPoint;
import Model.DrawModel.HistoricalTrack;
import Service.ShipCalculate;
import View.ChartFrame.MainWindow;
import View.DefaultCard.DefaultPanel;
import View.DrawPanel.ShowPanel;
import View.PublicWindow.WaitingPanel;
import View.PublicWindow.WrongAttention;
import View.TransSelectPicture.SelectPicturePanel;

/**
 * @author dn
 */
public class Home extends JFrame {
    // 切换页面使用布局
    public static CardLayout drawPanelSwitch = new CardLayout();
    public ArrayList<ShipCalculate> shipCalculateList = new ArrayList();
    public static int MPercent = 15;
    public static int XMove = 200;
    public static int YMove = 200;
    public static int CalSleepTime = 10;

    // 注册页面
    public static WaitingPanel waitingPanel = new WaitingPanel();
    public static volatile ShowPanel showContrailPanel = null;
    public static volatile SelectPicturePanel selectPicturePanel = null;

    // 注册计算组件
    public static volatile ShipCalculate shipCalculate;

    public Home() {
        initComponents();
        this.setVisible(true); // 设置可视化
        initDrawPanel(); // 初始化绘图页面
    }

    public void initDrawPanel() {

        setDefaultCloseOperation(EXIT_ON_CLOSE);

        this.setIconImage(new ImageIcon("src/main/resources/windowIcon.png").getImage());

        // 设置CardLayout，为后续页面切换做准备
        this.drawPanel.setLayout(drawPanelSwitch);
        // 添加默认页面
        this.drawPanel.add(new DefaultPanel(), "defaultPanel");
        this.drawPanel.add(waitingPanel, "waitingPanel");
        drawPanelSwitch.show(drawPanel, "defaultPanel"); // 设置默认显示
    }

    // 点击所有按钮前都要将已经创建的线程终止
    private void beforeClick() {
        // 设置等待页面
        drawPanelSwitch.show(drawPanel, "waitingPanel");
        waitingPanel.RandomPic();

        // 清除计算组件
        for (ShipCalculate item : shipCalculateList) {
            item.ShutDown();
        }
        shipCalculateList.clear();

        // 结束绘图组件自动刷新功能
        try {
            showContrailPanel.endUpdateComponent();
        } catch (NullPointerException e) {
            System.out.println("组件已被销毁,无法运行");
        }

        // 清除之前的Panel组件
        try {
            drawPanelSwitch.removeLayoutComponent(showContrailPanel);
            drawPanel.remove(showContrailPanel);
            showContrailPanel = null;
        } catch (NullPointerException ee) {
            System.out.println("不存在showContrailPanel");
        }

        // 缓冲时间
        try {
            Thread.sleep(100);
        } catch (InterruptedException interruptedException) {
            interruptedException.printStackTrace();
        }
    }

    /**
     * 创建绘图组件
     *
     * @param targetList          目标列表
     * @param shipsList           船舶名单
     * @param center              中心
     * @param historicalShipsList 历史船舶名单
     * @param sleepTime           睡眠时间
     */
    private void CreateDrawComponent(
            ArrayList<CalPoint> targetList,
            ArrayList<CalPoint> shipsList,
            ArrayList<CalPoint> VirtualTargetList,
            CalPoint center,
            ArrayList<HistoricalTrack> historicalShipsList,
            int sleepTime
    ) {
        showContrailPanel = new ShowPanel(
                targetList,
                shipsList,
                VirtualTargetList,
                center,
                historicalShipsList,
                sleepTime
        );
        // 将组件添加进布局
        drawPanel.add(showContrailPanel, "showContrailPanel");
        drawPanelSwitch.show(drawPanel, "showContrailPanel");
        showContrailPanel.setMultiplyAndMovement(MPercent, XMove, YMove);
        System.out.println("【页面切换完成】");
    }

    /**
     * 创建选择组件
     */
    private void CreateSelectComponent() {
        selectPicturePanel = new SelectPicturePanel();
        // 将组件添加进布局
        drawPanel.add(selectPicturePanel, "selectPicturePanel");
        drawPanelSwitch.show(drawPanel, "selectPicturePanel");
        System.out.println("【页面切换完成】");
    }

    /**
     * 画组件工作
     */
    private void DrawComponentWork() {
        try {
            // 启动绘图组件自动刷新功能
            showContrailPanel.beginUpdateComponent();
        } catch (NullPointerException e) {
            System.out.println("组件已被销毁,无法运行");
        }
    }

    /**
     * 创建计算组件
     *
     * @param targetList          目标列表
     * @param shipsList           船舶名单
     * @param center              中心
     * @param historicalShipsList 历史船舶名单
     * @param mode                模式
     */
    private void CreateCalComponent(
            ArrayList<CalPoint> targetList,
            ArrayList<CalPoint> shipsList,
            ArrayList<CalPoint> VirtualTargetList,
            CalPoint center,
            ArrayList<HistoricalTrack> historicalShipsList,
            CAL_MODE mode
    ) {
        // 调用工厂，获取对应的计算实例
        shipCalculate = CalculateClassFactory.getService(
                targetList,
                shipsList,
                VirtualTargetList,
                center,
                historicalShipsList,
                CalSleepTime,
                mode
        );
        System.out.println("成功创建" + shipCalculate.GetName());
        shipCalculateList.add(shipCalculate); // 将计算组件添加进队列中，便于统一清除

    }

    // 默认按钮点击
    private void defaultCardMouseClicked(MouseEvent e) {
        // TODO add your code here
        System.out.println("点击默认页面按钮");
        this.beforeClick();
        drawPanelSwitch.show(drawPanel, "defaultPanel");
    }

    // 一阶静态包围
    private void showOneMouseClicked(MouseEvent e) {
        // TODO add your code here
        System.out.println("点击队列转换示例按钮");
        // 运行前置操作，删除并销毁其它组件的线程
        this.beforeClick();

        new Thread(new Runnable(){
            @Override
            public void run() {
                // 定义交互数据
                ArrayList<CalPoint> TargetList = new ArrayList<>();
                ArrayList<CalPoint> ShipsList = new ArrayList<>();
                ArrayList<CalPoint> VirtualTargetList = new ArrayList<>();
                CalPoint p = new CalPoint();
                ArrayList<HistoricalTrack> HistoricalShipsList = new ArrayList<>();

                // 调用工厂，获取对应的计算实例
                CreateCalComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, CAL_MODE.FIRST_ORDER_STATIC);

                // 绘图实例
                // TODO:使用工厂生产对应的Panel
                CreateDrawComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, 10);

                // 计算组件启动计算
                CalculateClassFactory.RunComputingComponent(shipCalculate);

                // 使绘图组件工作
                DrawComponentWork();

            }
        }).start();
    }

    // 一阶动态包围
    private void showOne2MouseClicked(MouseEvent e) {
        // TODO add your code here
        System.out.println("点击一阶动态包围  按钮");
        // 运行前置操作，删除并销毁其它组件的线程
        this.beforeClick();

        new Thread(new Runnable(){
            @Override
            public void run() {
                // 定义交互数据
                ArrayList<CalPoint> TargetList = new ArrayList<>();
                ArrayList<CalPoint> ShipsList = new ArrayList<>();
                ArrayList<CalPoint> VirtualTargetList = new ArrayList<>();
                CalPoint p = new CalPoint();
                ArrayList<HistoricalTrack> HistoricalShipsList = new ArrayList<>();

                // 调用工厂，获取对应的计算实例
                CreateCalComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, CAL_MODE.FIRST_ORDER_MOVED);

                // 绘图实例
                // TODO:使用工厂生产对应的Panel
                CreateDrawComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, 10);

                // 计算组件启动计算
                CalculateClassFactory.RunComputingComponent(shipCalculate);

                // 使绘图组件工作
                DrawComponentWork();

            }
        }).start();
    }

    // 一阶静态自适应包围
    private void button2MouseClicked(MouseEvent e) {
        // TODO add your code here
        System.out.println("点击 一阶静态自适应包围  按钮");
        // 运行前置操作，删除并销毁其它组件的线程
        this.beforeClick();

        new Thread(new Runnable(){
            @Override
            public void run() {
                // 定义交互数据
                ArrayList<CalPoint> TargetList = new ArrayList<>();
                ArrayList<CalPoint> ShipsList = new ArrayList<>();
                ArrayList<CalPoint> VirtualTargetList = new ArrayList<>();
                CalPoint p = new CalPoint();
                ArrayList<HistoricalTrack> HistoricalShipsList = new ArrayList<>();

                // 调用工厂，获取对应的计算实例
                CreateCalComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, CAL_MODE.FIRST_ORDER_ADAPTION_STATIC);

                // 绘图实例
                // TODO:使用工厂生产对应的Panel
                CreateDrawComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, 10);

                // 计算组件启动计算
                CalculateClassFactory.RunComputingComponent(shipCalculate);

                // 使绘图组件工作
                DrawComponentWork();

            }
        }).start();
    }

    // 一阶动态自适应包围
    private void button3MouseClicked(MouseEvent e) {
        // TODO add your code here
        System.out.println("点击 一阶动态自适应包围  按钮");
        // 运行前置操作，删除并销毁其它组件的线程
        this.beforeClick();

        new Thread(new Runnable(){
            @Override
            public void run() {
                // 定义交互数据
                ArrayList<CalPoint> TargetList = new ArrayList<>();
                ArrayList<CalPoint> ShipsList = new ArrayList<>();
                ArrayList<CalPoint> VirtualTargetList = new ArrayList<>();
                CalPoint p = new CalPoint();
                ArrayList<HistoricalTrack> HistoricalShipsList = new ArrayList<>();

                // 调用工厂，获取对应的计算实例
                CreateCalComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, CAL_MODE.FIRST_ORDER_ADAPTION_MOVING);

                // 绘图实例
                CreateDrawComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, 10);

                // 计算组件启动计算
                CalculateClassFactory.RunComputingComponent(shipCalculate);

                // 使绘图组件工作
                DrawComponentWork();

            }
        }).start();
    }



    // 间歇通信
    private void checkCardMouseClicked(MouseEvent e) {
        // TODO add your code here
        System.out.println("点击间歇通信按钮");
        this.beforeClick();

        new Thread(new Runnable(){
            @Override
            public void run() {
                // 定义交互数据
                ArrayList<CalPoint> TargetList = new ArrayList<>();
                ArrayList<CalPoint> ShipsList = new ArrayList<>();
                ArrayList<CalPoint> VirtualTargetList = new ArrayList<>();
                CalPoint p = new CalPoint();
                ArrayList<HistoricalTrack> HistoricalShipsList = new ArrayList<>();

                // 调用工厂，获取对应的计算实例
                CreateCalComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, CAL_MODE.INTERMITTENT_COM);

                // 绘图实例
                // TODO:使用工厂生产对应的Panel
                CreateDrawComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, 10);

                // 计算组件启动计算
                CalculateClassFactory.RunComputingComponent(shipCalculate);

                // 使绘图组件工作
                DrawComponentWork();

            }
        }).start();
    }

    // 二阶静态包围
    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
        System.out.println("点击二阶静态包围按钮");
        this.beforeClick();

        new Thread(new Runnable(){
            @Override
            public void run() {
                // 定义交互数据
                ArrayList<CalPoint> TargetList = new ArrayList<>();
                ArrayList<CalPoint> ShipsList = new ArrayList<>();
                ArrayList<CalPoint> VirtualTargetList = new ArrayList<>();
                CalPoint p = new CalPoint();
                ArrayList<HistoricalTrack> HistoricalShipsList = new ArrayList<>();

                // 调用工厂，获取对应的计算实例
                CreateCalComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, CAL_MODE.SECOND_STATIC);

                // 绘图实例
                // TODO:使用工厂生产对应的Panel
                CreateDrawComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, 10);

                // 计算组件启动计算
                CalculateClassFactory.RunComputingComponent(shipCalculate);

                // 使绘图组件工作
                DrawComponentWork();

            }
        }).start();
    }

    // 自定义图片转换按钮点击
    private void button4MouseClicked(MouseEvent e) {
        // TODO add your code here
        System.out.println("点击自定义图片按钮");
        this.beforeClick();
        CreateSelectComponent();

    }
    // 模拟按钮点击

    private void button5MouseClicked(MouseEvent e) {
        this.beforeClick();

        // 备份回调对象
        JFrame backTarget = this;

        new Thread(new Runnable(){
            @Override
            public void run() {
                // 定义交互数据
                ArrayList<CalPoint> ShipsList = new ArrayList<>();
                ArrayList<HistoricalTrack> HistoricalShipsList = new ArrayList<>();
                ArrayList<CalPoint> VirtualTargetList = new ArrayList<>();
                // 调用工厂，获取对应的计算实例
                try {
                    shipCalculate = selectPicturePanel.GetService(null, ShipsList,null,null, HistoricalShipsList, CalSleepTime);
                    if (shipCalculate == null) throw new NullPointerException();
                    List<Double> shipMinDis = new ArrayList<>();
                    List<Double> shipEvDis= new ArrayList<>();
                    CalculateClassFactory.SetChartDataSource(shipMinDis, shipEvDis);
                } catch (Exception e) {
                    e.printStackTrace();
                    new WrongAttention().setVisible(true);
                    return;
                }

                // 绘图实例
                CreateDrawComponent(null, ShipsList,null, null, HistoricalShipsList, 10);

                MultiplySlider.setValue(3);
                slider1.setValue(51);
                slider2.setValue(51);
                MultiplySlider2.setValue(80);

                // 计算组件启动计算
                CalculateClassFactory.RunComputingComponentWithCallBack(shipCalculate, backTarget, "ejectChartFrame");

                // 使绘图组件工作
                DrawComponentWork();
            }
        }).start();
    }
    // 弹出表格窗口
    public void ejectChartFrame() {
        System.out.println("回调函数成功运行！");

        List<Double> minData =  CalculateClassFactory.GetCalculateComponentData().getShipMinDis();
        List<Double> evData =  CalculateClassFactory.GetCalculateComponentData().getShipEvDis();
        List<Double> xData = new ArrayList<>();
        for (int itemNum = 0; itemNum < minData.size(); itemNum ++) {
            xData.add((double) itemNum);
        }

        new MainWindow("最短距离",  xData, minData, null).setVisible(true);
        new MainWindow("平均距离",  xData, evData, null).setVisible(true);
    }

    // 一阶不等数量包围按钮点击
    private void button6MouseClicked(MouseEvent e) {

        this.beforeClick();

        // 备份回调对象
        JFrame backTarget = this;

        new Thread(new Runnable(){
            @Override
            public void run() {
                // 定义交互数据
                ArrayList<CalPoint> TargetList = new ArrayList<>();
                ArrayList<CalPoint> ShipsList = new ArrayList<>();
                ArrayList<CalPoint> VirtualTargetList = new ArrayList<>();
                CalPoint p = new CalPoint();
                ArrayList<HistoricalTrack> HistoricalShipsList = new ArrayList<>();

                // 调用工厂，获取对应的计算实例
                CreateCalComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, CAL_MODE.FIRST_ORDER_UN);

                // 判断计算组件的准备状态，若未准备成功则直接跳过计算及渲染步骤
                if (shipCalculate.GetPrepareState()) {

                    // 绘图实例
                    CreateDrawComponent(TargetList, ShipsList,VirtualTargetList , p, HistoricalShipsList, 10);

                    // 计算组件启动计算
//                    CalculateClassFactory.RunComputingComponent(shipCalculate);
                    CalculateClassFactory.RunComputingComponentWithCallBack(shipCalculate, backTarget, "ejectSurroundChartFrame");



                    // 使绘图组件工作
                    MultiplySlider.setValue(12);
                    slider1.setValue(53);
                    slider2.setValue(54);
                    MultiplySlider2.setValue(90);
                    DrawComponentWork();

                }
            }
        }).start();
    }
    // 弹出表格窗口
    public void ejectSurroundChartFrame() {
        System.out.println("回调函数成功运行！");

        List<Double> surround =  CalculateClassFactory.GetCalculateComponentData().getSurround();
        System.out.println("surround !!!!!" + surround.size());
        List<Double> time = new ArrayList<>();
        for (int itemNum = 0; itemNum < surround.size(); itemNum ++) {
//            time.add((double) itemNum*0.02);
            time.add((double) itemNum*0.005);
        }

        new MainWindow("包围情况Surround",  time, surround).setVisible(true);
//        new MainWindow("平均距离",  xData, evData, null).setVisible(true);
    }


    // 一阶不等数量动态包围按钮点击
    private void button7MouseClicked(MouseEvent e) {
        // TODO add your code here

        this.beforeClick();

        // 备份回调对象
        JFrame backTarget = this;

        new Thread(new Runnable(){
            @Override
            public void run() {
                // 定义交互数据
                ArrayList<CalPoint> TargetList = new ArrayList<>();
                ArrayList<CalPoint> ShipsList = new ArrayList<>();
                ArrayList<CalPoint> VirtualTargetList = new ArrayList<>();
                CalPoint p = new CalPoint();
                ArrayList<HistoricalTrack> HistoricalShipsList = new ArrayList<>();

                // 调用工厂，获取对应的计算实例
                CreateCalComponent(TargetList, ShipsList,VirtualTargetList, p, HistoricalShipsList, CAL_MODE.FIRST_ORDER_UN_MOVING);

                // 判断计算组件的准备状态，若未准备成功则直接跳过计算及渲染步骤
                if (shipCalculate.GetPrepareState()) {

                    // 绘图实例
                    CreateDrawComponent(TargetList, ShipsList,VirtualTargetList , p, HistoricalShipsList, 10);

                    // 计算组件启动计算
//                    CalculateClassFactory.RunComputingComponent(shipCalculate);
                    CalculateClassFactory.RunComputingComponentWithCallBack(shipCalculate, backTarget, "ejectSurroundChartFrame");

                    // 使绘图组件工作
                    MultiplySlider.setValue(12);
                    slider1.setValue(53);
                    slider2.setValue(54);
                    MultiplySlider2.setValue(90);
                    DrawComponentWork();

                }
            }
        }).start();

    }



    private void MultiplySliderStateChanged(ChangeEvent e) {
        // TODO add your code here
        System.out.println("Slider!!!!!" + this.MultiplySlider.getValue());
        MPercent = this.MultiplySlider.getValue()/2;
        try {
            showContrailPanel.setMultiplyAndMovement(MPercent, XMove, YMove);
        } catch (NullPointerException nu) {
            System.out.println("组件不存在");
        }

    }

    private void slider1StateChanged(ChangeEvent e) {
        // TODO add your code here
        System.out.println("Slider Move!!!!!" + this.slider1.getValue());
        XMove = (this.slider1.getValue() - 50 ) * 100;
        try {
            showContrailPanel.setMultiplyAndMovement(MPercent, XMove, YMove);
        } catch (NullPointerException nu) {
            System.out.println("组件不存在");
        }
    }

    private void slider2StateChanged(ChangeEvent e) {
        // TODO add your code here
        System.out.println("Slider Move!!!!!" + this.slider2.getValue());
        YMove = (this.slider2.getValue() - 50 ) * 100;
        try {
            showContrailPanel.setMultiplyAndMovement(MPercent, XMove, YMove);
        } catch (NullPointerException nu) {
            System.out.println("组件不存在");
        }
    }

    private void MultiplySlider2StateChanged(ChangeEvent e) {
        // TODO add your code here
        System.out.println("Slider Move!!!!!" + this.MultiplySlider2.getValue());
        CalSleepTime = (this.MultiplySlider2.getValue() / 20) * 10 + 1;
        try {
            shipCalculate.SetCalSpeed(CalSleepTime);
        } catch (NullPointerException nu) {
            System.out.println("组件不存在");
        }
    }






    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        windowPanel = new JPanel();
        showOne = new JButton();
        checkCard = new JButton();
        drawPanel = new JPanel();
        defaultCard = new JButton();
        MultiplySlider = new JSlider();
        label1 = new JLabel();
        label2 = new JLabel();
        showOne2 = new JButton();
        slider1 = new JSlider();
        slider2 = new JSlider();
        button1 = new JButton();
        button2 = new JButton();
        button3 = new JButton();
        label3 = new JLabel();
        label4 = new JLabel();
        MultiplySlider2 = new JSlider();
        label5 = new JLabel();
        button4 = new JButton();
        separator1 = new JSeparator();
        separator2 = new JSeparator();
        separator3 = new JSeparator();
        separator4 = new JSeparator();
        button5 = new JButton();
        separator5 = new JSeparator();
        separator6 = new JSeparator();
        button6 = new JButton();
        button7 = new JButton();

        //======== this ========
        setTitle("\u4eff\u771f\u7cfb\u7edf");
        setResizable(false);
        Container contentPane = getContentPane();
        contentPane.setLayout(new CardLayout());

        //======== windowPanel ========
        {
            windowPanel.setLayout(null);

            //---- showOne ----
            showOne.setText("\u4e00\u9636\u9759\u6001\u5305\u56f4");
            showOne.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    showOneMouseClicked(e);
                }
            });
            windowPanel.add(showOne);
            showOne.setBounds(15, 80, 120, showOne.getPreferredSize().height);

            //---- checkCard ----
            checkCard.setText("\u95f4\u6b47\u901a\u4fe1");
            checkCard.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    checkCardMouseClicked(e);
                }
            });
            windowPanel.add(checkCard);
            checkCard.setBounds(15, 275, 120, checkCard.getPreferredSize().height);

            //======== drawPanel ========
            {
                drawPanel.setLayout(new CardLayout());
            }
            windowPanel.add(drawPanel);
            drawPanel.setBounds(185, 0, 770, 770);

            //---- defaultCard ----
            defaultCard.setText("\u9996\u9875");
            defaultCard.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    defaultCardMouseClicked(e);
                }
            });
            windowPanel.add(defaultCard);
            defaultCard.setBounds(15, 30, 120, defaultCard.getPreferredSize().height);

            //---- MultiplySlider ----
            MultiplySlider.setValue(15);
            MultiplySlider.addChangeListener(e -> MultiplySliderStateChanged(e));
            windowPanel.add(MultiplySlider);
            MultiplySlider.setBounds(40, 700, 90, 10);

            //---- label1 ----
            label1.setText("\u653e\u5927\u500d\u6570\uff1a");
            windowPanel.add(label1);
            label1.setBounds(new Rectangle(new Point(10, 675), label1.getPreferredSize()));

            //---- label2 ----
            label2.setText("\u4f4d\u79fb\uff1a");
            windowPanel.add(label2);
            label2.setBounds(10, 715, 40, label2.getPreferredSize().height);

            //---- showOne2 ----
            showOne2.setText("\u4e00\u9636\u52a8\u6001\u5305\u56f4");
            showOne2.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    showOne2MouseClicked(e);
                }
            });
            windowPanel.add(showOne2);
            showOne2.setBounds(15, 115, 120, showOne2.getPreferredSize().height);

            //---- slider1 ----
            slider1.addChangeListener(e -> slider1StateChanged(e));
            windowPanel.add(slider1);
            slider1.setBounds(35, 735, 95, 10);

            //---- slider2 ----
            slider2.addChangeListener(e -> slider2StateChanged(e));
            windowPanel.add(slider2);
            slider2.setBounds(35, 750, 95, 9);

            //---- button1 ----
            button1.setText("\u4e8c\u9636\u9759\u6001\u5305\u56f4");
            button1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button1MouseClicked(e);
                }
            });
            windowPanel.add(button1);
            button1.setBounds(15, 230, 120, button1.getPreferredSize().height);

            //---- button2 ----
            button2.setText("\u4e00\u9636\u81ea\u9002\u5e94\u9759\u6001\u5305\u56f4");
            button2.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button2MouseClicked(e);
                }
            });
            windowPanel.add(button2);
            button2.setBounds(15, 150, 120, button2.getPreferredSize().height);

            //---- button3 ----
            button3.setText("\u4e00\u9636\u81ea\u9002\u5e94\u52a8\u6001\u5305\u56f4");
            button3.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button3MouseClicked(e);
                }
            });
            windowPanel.add(button3);
            button3.setBounds(15, 185, 120, button3.getPreferredSize().height);

            //---- label3 ----
            label3.setText("x:");
            windowPanel.add(label3);
            label3.setBounds(15, 730, 20, label3.getPreferredSize().height);

            //---- label4 ----
            label4.setText("y:");
            windowPanel.add(label4);
            label4.setBounds(15, 745, 20, 17);

            //---- MultiplySlider2 ----
            MultiplySlider2.addChangeListener(e -> MultiplySlider2StateChanged(e));
            windowPanel.add(MultiplySlider2);
            MultiplySlider2.setBounds(40, 665, 90, 10);

            //---- label5 ----
            label5.setText("\u901f\u5ea6\uff1a");
            windowPanel.add(label5);
            label5.setBounds(new Rectangle(new Point(10, 640), label5.getPreferredSize()));

            //---- button4 ----
            button4.setText("\u81ea\u5b9a\u4e49\u56fe\u7247\u961f\u5217\u8f6c\u6362");
            button4.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button4MouseClicked(e);
                }
            });
            windowPanel.add(button4);
            button4.setBounds(15, 325, 120, button4.getPreferredSize().height);

            //---- separator1 ----
            separator1.setPreferredSize(new Dimension(20, 3));
            windowPanel.add(separator1);
            separator1.setBounds(5, 315, 135, 8);

            //---- separator2 ----
            separator2.setPreferredSize(new Dimension(20, 3));
            windowPanel.add(separator2);
            separator2.setBounds(5, 265, 135, 8);

            //---- separator3 ----
            separator3.setPreferredSize(new Dimension(20, 3));
            windowPanel.add(separator3);
            separator3.setBounds(5, 220, 135, 8);

            //---- separator4 ----
            separator4.setPreferredSize(new Dimension(20, 3));
            windowPanel.add(separator4);
            separator4.setBounds(5, 70, 135, 8);

            //---- button5 ----
            button5.setText("\u542f\u52a8\u4eff\u771f");
            button5.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button5MouseClicked(e);
                }
            });
            windowPanel.add(button5);
            button5.setBounds(15, 360, 120, button5.getPreferredSize().height);

            //---- separator5 ----
            separator5.setPreferredSize(new Dimension(20, 3));
            windowPanel.add(separator5);
            separator5.setBounds(0, 395, 135, 8);

            //---- separator6 ----
            separator6.setPreferredSize(new Dimension(20, 3));
            windowPanel.add(separator6);
            separator6.setBounds(0, 630, 135, 8);

            //---- button6 ----
            button6.setText("\u4e00\u9636\u4e0d\u7b49\u6570\u91cf\u5305\u56f4");
            button6.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button6MouseClicked(e);
                }
            });
            windowPanel.add(button6);
            button6.setBounds(15, 405, 120, button6.getPreferredSize().height);

            //---- button7 ----
            button7.setText("\u4e00\u9636\u4e0d\u7b49\u6570\u91cf\u52a8\u6001\u5305\u56f4");
            button7.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button7MouseClicked(e);
                }
            });
            windowPanel.add(button7);
            button7.setBounds(10, 440, 135, 30);

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < windowPanel.getComponentCount(); i++) {
                    Rectangle bounds = windowPanel.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = windowPanel.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                windowPanel.setMinimumSize(preferredSize);
                windowPanel.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(windowPanel, "card1");
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel windowPanel;
    private JButton showOne;
    private JButton checkCard;
    private JPanel drawPanel;
    private JButton defaultCard;
    private JSlider MultiplySlider;
    private JLabel label1;
    private JLabel label2;
    private JButton showOne2;
    private JSlider slider1;
    private JSlider slider2;
    private JButton button1;
    private JButton button2;
    private JButton button3;
    private JLabel label3;
    private JLabel label4;
    private JSlider MultiplySlider2;
    private JLabel label5;
    private JButton button4;
    private JSeparator separator1;
    private JSeparator separator2;
    private JSeparator separator3;
    private JSeparator separator4;
    private JButton button5;
    private JSeparator separator5;
    private JSeparator separator6;
    private JButton button6;
    private JButton button7;
    // JFormDesigner - End of variables declaration  //GEN-END:variables

    public static void main(String[] args) {
        Home home = new Home();
    }
}
